
<%
	task.doTask();
	Record ref = task.wr_ref;
%>

<link href="style.css" rel="stylesheet" type="text/css">

<script language="javascript">

function listViewClicked()
{
	setValue("view",0);
	doPost();
}

function new_WR_WC()
{
	var order_type = <%=task.order_type%>;
	var order_id = getValue("order_id");
	if (order_id <= 0) {
		var msg = "Please select Order Ref before creating " + (order_type==2?"WC":"WR");
		alert(msg);
		return;
	}
	var new_wr = "<%=task.getNew_WR()%>";
	var new_qr = "<%=task.getNew_QR()%>";
	var idx = addNewListItem(document.formMain.wr_id,new_wr);
	setText("ref_number_",new_wr);
	//setValue("ref_number",new_wr);
	setText("qr_ref_",new_qr);
	setText("wr_date_","");
	setText("wr_time_","");
	//
	//setSelected("order_id",0);
	for (var i = 1; ; i++) {
		var wn = getObj("wn_" + i)
		if (wn == null) break;
		//wn.style.display = "none";
	}

}

function sumNetWeight()
{
	var sum = 0;
	for (var i = 1; ; i++) {
		var wn = getObj("wn_" + i);
		if (wn == null) break;
		var cbx = getObj("wn_sel_" + i + "_");
		if (cbx != null && cbx.checked) {
			sum += parseFloat(getText("net_weight_" + i));
		}
	}
	return formatNumber(sum,4,true);
}

function wnSelectedAll(cbx)
{
	for (var i = 1; ; i++) {
		var wn = getObj("wn_" + i)
		if (wn == null) break;
		var wn_sel = getObj("wn_sel_" + i + "_");
		wn_sel.checked = cbx.checked;
		cbxClick(wn_sel);
	}
}

function doUpdate()
{
	if (getValue('wr_id') != 0) doTask(1)
}

function delete_WR_WC()
{
	if (!confirm("Are you sure to delete the item " + getSelectedText('wr_id'))) return;
	doTask(2);
}

</script>

<form method="POST" name="formMain" action="" onSubmit="">				  

<table width="100%"  border="0" class="style2">
	<tr class="style1" bgcolor="#EEEEEE">
	  <td width="19%" align="center"><label id="e11">WR Ref</label></td>
	  <td width="81%"><label id="e12">Detail</label></td>
  </tr>
	<tr>
	  <td height="336" valign="top"><table width="100%"  border="0">
        <tr valign="top">
          <td><select name="wr_id" size=15 class="style2" id="wr_id" style="width:100%;" onChange="doPost()">
		  	<option value="0" selected></option>
            <%task.getResponse().setOptionX(task.getWR_WC_List());%>
			<%task.getResponse().setSelected("wr_id",task.wr_id);%>
          </select></td>
        </tr>

        <tr>
          <td height="20">
		  	<a href="javascript:new_WR_WC()"><img src="images/new.gif" border="0" width="15" height="15"></a>
			<a href="javascript:delete_WR_WC()"><img src="images/delete.gif" width="15" height="15" border="0"></a>
		  </td>
        </tr>
      </table></td>
	  <td valign="top"><table width="100%"   border="1" cellpadding="0" cellspacing="0">
  		<tr>
    		<td colspan="2"><table width="100%"  border="0" cellspacing="0" cellpadding="0" class="style2">
              <tr>
                <td width="20%">&nbsp;</td>
                <td width="1%">&nbsp;</td>
                <td width="29%">&nbsp;</td>
                <td width="20%">&nbsp;</td>
                <td width="1%">&nbsp;</td>
                <td width="27%">&nbsp;</td>
                <td width="2%">&nbsp;</td>
              </tr>
              <tr>
                <td align="right" height="22"><label id="e21">Ref Number</label></td>
                <td>&nbsp;</td>
                <td style="font-weight:bold"><%=ref.getString("ref_number")%></td>
                <td align="right"><label id="e22">Contract Ref</label></td>
                <td>&nbsp;</td>
                <td style="font-weight:bold"><%=ref.getString("contract_ref_number")%></td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td align="right" height="22"><label id="e23">Order Ref</label></td>
                <td>&nbsp;</td>
                <td><select name="order_id" id="order_id" onChange="setValue('wr_id',0);doPost()" size=1 style="font-family:Arial; font-size:12px; width:150px;">
                  <option value="0" selected>All</option>
                  <%task.getResponse().setOption(task.getOrderList());%>
                  <%task.getResponse().setSelected("order_id",task.order_id);%>
                </select></td>
                <td align="right"><label id="e24">Client</label></td>
                <td>&nbsp;</td>
                <td style="font-weight:bold"><%=ref.getString("client")%></td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td align="right" height="22"><label id="e25">Date</label></td>
                <td>&nbsp;</td>
                <td style="font-weight:bold"><%=ref.getDate("wr_date")%></td>
                <td align="right"><label id="e26">Supplier</label></td>
                <td>&nbsp;</td>
                <td style="font-weight:bold"><%=ref.getString("supplier")%></td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td align="right" height="22"><label id="e27">Time</label></td>
                <td>&nbsp;</td>
                <td style="font-weight:bold"><%=ref.getTime("wr_time")%></td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td align="right"><label id="e28">Remark</label></td>
                <td>&nbsp;</td>
                <td colspan="4"><textarea name="remark" rows="4" class="style2" id="remark" style="width:100%"><%=ref.getString("remark")%></textarea></td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td colspan="7"><div style="BORDER:0px ; OVERFLOW: auto; WIDTH: 100%; HEIGHT: 180px; display:true">
				<table width="100%"  border="0" class="style2">
                  <tr bgcolor="#EEEEEE" align="center" style="font-weight:bold">
                    <td><label id="e31">WN Ref</label></td>
                    <td><label id="e32">QR Ref</label></td>
                    <td><label id="e33">Quality</label></td>
                    <td><label id="e34">Grade</label></td>
                    <td><label id="e35">Tons</label></td>
                    <td><label id="e36">Sel</label><br>
                        <input type="checkbox" name="wn_sel_all_" id="wn_sel_all_" value="0" onClick="wnSelectedAll(this);setText('total_net_weight',sumNetWeight());"></td>
                  </tr>
                  <%
	ResultSet rs = task.getWN_List();
	while(rs.next()) {
		int i = rs.getRow();
		float net_weight  = rs.getFloat("net_weight")/1000;
%>
                  <tr id="wn_<%=i%>" class="style11" onClick="highlightOn(this);">
                    <input type="hidden" name="wn_id_<%=i%>" id="wn_id_<%=i%>" value="<%=rs.getLong("id")%>">
                    <td><%=rs.getString("ref_number")%></td>
                    <td><%=rs.getString("qr_ref_number")%></td>
                    <td><%=rs.getString("quality")%></td>
                    <td><%=rs.getString("grade")%></td>
                    <td align="right"><label id="net_weight_<%=i%>"><%=Utils.numberToStr(net_weight)%></label></td>
                    <td align="center"><input type="checkbox" name="wn_sel_<%=i%>_" id="wn_sel_<%=i%>_" value="<%=i%>"  <%=rs.getInt("wr_id")>0?"checked":""%> onClick="cbxClick(this);setText('total_net_weight',sumNetWeight())"></td>
                    <input type="hidden" name="wn_sel_<%=i%>" id="wn_sel_<%=i%>" value="<%=rs.getInt("wr_id")>0?1:0%>">
                  </tr>
                  <%
	}
	rs.close();
%>
					<tr>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
						<td align="right" style="font-weight:bold"><label id="e41">Total</label></td>
						<td align="right" style="font-weight:bold"><label id="total_net_weight">0.0000</label></td>
						<td>&nbsp;</td>
					</tr>
                </table>
				</div></td>
                </tr>
              <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td align="right"><label id="e42">Completed</label></td>
                <td>&nbsp;</td>
                <td><input type="checkbox" name="completed_" id="completed_" <%=ref.getIntValue("status")==2?"checked":""%> onClick="cbxClick(this,2);"></td>
				    <input type="hidden"   name="completed"  id="completed"  value="<%=ref.getIntValue("status")%>">
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
            </table></td>
  		</tr>
	</table></td>
  </tr>
	<tr>
	  <td>&nbsp;</td>
		<td><table width="100%"  border="0">
          <tr>
            <td><a href="javascript:doUpdate()"><img src="images/update.gif" width="15" height="15" border="0"></a></td>
            <td align="right"><img id="bt_card_view" src="images/listview.jpg" width="55" height="18" onClick="listViewClicked();"></td>
          </tr>
        </table></td>
	</tr>
	<input type="hidden" name="uid"  id="uid"  value="<%=user.getuid()%>">
	<input type="hidden" name="task_id"  id="task_id"  value="0">
	<input type="hidden" name="view" id="view" value="<%=task.getRequest().getIntValue("view")%>">

</table>
</form>

<script language="javascript">
	setText('total_net_weight',sumNetWeight());
</script>

<label id="v11" style="display:none">Ch&#7913;ng t&#7915;</label>
<label id="v12" style="display:none">Chi ti&#7871;t</label>

<label id="v21" style="display:none">Ch&#7913;ng t&#7915;</label>
<label id="v22" style="display:none">H&#7907;p &#273;&#7891;ng</label>
<label id="v23" style="display:none">L&#7879;nh th&#7921;c hi&#7879;n</label>
<label id="v24" style="display:none">Ch&#7911; h&agrave;ng</label>
<label id="v25" style="display:none">Ng&agrave;y</label>
<label id="v26" style="display:none">Nh&agrave; cung &#7913;ng</label>
<label id="v27" style="display:none">Gi&#7901;</label>
<label id="v28" style="display:none">Ghi ch&uacute;</label>

<label id="v31" style="display:none">Phi&#7871;u c&acirc;n</label>
<label id="v32" style="display:none">Tham chi&#7871;u<br>Ch&#7845;t l&#432;&#7907;ng</label>
<label id="v33" style="display:none">Ch&#7845;t l&#432;&#7907;ng</label>
<label id="v34" style="display:none">Lo&#7841;i h&agrave;ng</label>
<label id="v35" style="display:none">S&#7889; l&#432;&#7907;ng<br>(T&#7845;n)</label>
<label id="v36" style="display:none">Ch&#7885;n</label>

<label id="v41" style="display:none">C&#7897;ng</label>
<label id="v42" style="display:none">K&#7871;t th&uacute;c</label>
